package cn.bdqn.util;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by Administrator on 2018/8/17.
 */
public class Md5Util {
    //给我一个字符串，加密完我再给你
    public static String getSuibian(String oldPassword) {
        String newPwd = null;
        StringBuilder sb=new StringBuilder();
        try {
            //BASE64Encoder避免乱码
            BASE64Encoder b64=new BASE64Encoder();
            b64.encode(oldPassword.getBytes());
            //MessageDigest md5加密
            MessageDigest md5 = MessageDigest.getInstance("md5");
            byte[] bs = md5.digest(oldPassword.getBytes());
            newPwd=new String(bs);
            for(int i=0;i<bs.length;i++){
                int a=bs[i];
                System.out.println(a);
                if(a<0){
                    a+=256; //-128 127
                }//规则自定
                sb.append(Integer.toHexString(a%16));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(getSuibian("123456"));
    }
}
